﻿using System;
using System.Windows.Forms;
using Microsoft.Win32;
using static System.Net.Mime.MediaTypeNames;

class Program
{
    static void Main()
    {
        SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
        Application.Run(); // Keeps the application running to catch events  
    }

    static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
    {
        if (e.Reason == SessionEndReasons.SystemShutdown) {
            Console.WriteLine("系统正在关机");
        }
        else if (e.Reason == SessionEndReasons.Logoff) {
            Console.WriteLine("用户注销");
        }
        else if (e.Reason == SessionEndReasons.SystemReboot) {
            Console.WriteLine("系统正在重启");
        }
    }
}